//
// Created by none98 on 2021/9/10.
//

#ifndef LOGINSERVER_ACCEPTOR_H
#define LOGINSERVER_ACCEPTOR_H

#include <memory>
#include <unistd.h>
#include <spdlog/spdlog.h>
#include "CallBacks.h"

class EventLoop;
class Channel;
class Acceptor {
public:
    Acceptor(const std::string &address, int port, EventLoop* loop);

    ~Acceptor();
    void HandleRead();
    void HandleError();
    void SetNewConnection(const TcpCallBack &callBack){
        this->newConnectionCallBack = callBack;
    }

    void SetRegisterInServerCallBack(const RegisterCallBack &callBack){
        this->registerConnCallBack=callBack;
    }

    void SetCloseInServerCallBack(const CloseInServerCallBack &callBack){
        this->closeConnCallBack = callBack;
    }

private:
    int fd;
    int port;
    std::unique_ptr<Channel> channel;
    EventLoop* loop;
    //TcpServer connection callback;
    RegisterCallBack registerConnCallBack;
    CloseInServerCallBack closeConnCallBack;


    //user connection callback
    TcpCallBack newConnectionCallBack;
};


#endif //LOGINSERVER_ACCEPTOR_H
